package practioce;

/**
 * create by Sun
 * 2018/8/31
 */
public class teset {
    public static String longestCommonPrefix(String[] strs) {
        if(strs.length==0) return "";
        StringBuilder sb=new StringBuilder();
        int flag=0;
        for(int i=0;i<strs[0].length();i++){
            char c=strs[0].charAt(i);
            for(String s:strs){
                if(s.length()==i){
                    flag=1;
                    break;
                }
                if(s.charAt(i)!=c) {
                   flag=1;
                   break;
                }
            }
            if(flag==1){
                break;
            }
            sb.append(c);

        }
       return sb.toString();

    }

    public static int maxArea(int[] height) {
        int left=0;
        int right=height.length-1;
        int max=0;
        while (left<right){
            max=Math.max(max,
                    (Math.min(height[left],height[right])*(right-left)));
            if(height[left]<height[right]){
                left++;
            }else{
                right--;
            }
        }
        return max;
    }

    public  static  int reverse(int x) {

        int flag=1;
        if(x<0){
            x=-x;
            flag=-1;
        }
        String s=String.valueOf(x);
        int len=s.length();
        int[] a=new int[len];
        char[] chars=s.toCharArray();
        int i,j;
        for (i=0;i<len/2;i++){
            char t=chars[i];
            chars[i]=chars[len-1-i];
            chars[len-i-1]=t;
        }

        //自动转换啊  牛逼
        int sum=0;
        try{
            sum=Integer.parseInt(String.valueOf(chars));
        }catch (Exception e){
            return 0;
        }


        return sum*flag;
    }
    public static boolean isPalindrome(int x) {
        if(x<0)
            return false;
        char[] chars=String.valueOf(x).toCharArray();
        int length = chars.length;
        int i=0;
        while (i<length/2){
            if(chars[i]==chars[length-i-1]){
                i++;
            }
            else {
                break;
            }
        }
        System.out.println(i);
        if(i==length/2)return true;
        else return false;
    }
    public static void main(String[] args) {
        System.out.println(isPalindrome(121));
    }
}
